﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Framework.Common
{
    /// <summary>
    /// 单例模式延迟加载
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public sealed class Singleton<T>
    {
        Singleton()
        {
        }

        public static T Instance
        {
            get
            {
                return Nested.instance;
            }
        }

        private class Nested
        {
            // Explicit static constructor to tell C# compiler
            // not to mark type as beforefieldinit
            static Nested()
            {
            }

            internal static readonly T instance = (T)Activator.CreateInstance(typeof(T), true);
        }
    }

}
